using System;
using System.Collections.Generic;
using MTUnity.Utils;
using Script.Data;
using UnityEngine;
using UnityEngine.UI;

namespace Script.UI.Panel.OverviewWnd2
{
    public class SliderGroup : MonoBehaviour
    {
        public Text sliderName;
        public List<Slider> sliderList;
        public List<Text> sliderValue;


        public void Refresh(List<MTJSONObject> l, float max, float min)
        {
            for (int i = 0; i < l.Count; i++)
            {
                if (sliderList.Count <= i)
                {
                    continue;;
                }
                var o = l[i];
                var conf = PositionConf.GetConfByServerId(o["loctionId"].i);
                var e = (int)Enum.Parse(typeof(SliderModule.TypeName), o["typeName"].s);
                if (conf == null)
                {
                    Debug.LogError("服务器的id在本地找不到" + o["loctionId"].i);
                    continue;
                }
                sliderName.text = conf.notecn;
                if (Mathf.Abs(o["num"].f - 0 ) < 0.00001)
                {
                    sliderList[e].value = 0;
                }
                else
                {
                    sliderList[e].value = o["num"].f / min * 0.9f;
                }

                sliderValue[i].text = o["num"].f.ToString();
            }

            for (int i = l.Count ; i < sliderList.Count; i++)
            {
                sliderList[i].value = 0;
                sliderValue[i].text = 0.ToString();
            }

        }
    }
}